const axios = require('axios')

module.exports = {
    namespaced: true,
    state: {
        pageData: {
            pageSize: 3,
            currentPage: 1,
            pages: 0,
            total: 0,
            rows: [],
        },
        pageData2: {
            pageSize: 3,
            currentPage: 1,
            pages: 0,
            total: 0,
            rows: [],
        },
        pageData3: {
            pageSize: 3,
            currentPage: 1,
            pages: 0,
            total: 0,
            rows: [],
        },
        pageData4: {
            pageSize: 3,
            currentPage: 1,
            pages: 0,
            total: 0,
            rows: [],
        },
        pageData5: {
            pageSize: 3,
            currentPage: 1,
            pages: 0,
            total: 0,
            rows: [],
        },
    },
    mutations: {
        fz(state, data) {
            state.pageData.rows = data.rows
            state.pageData.total = data.total
        },
        fz2(state, data) {
            state.pageData2.rows = data.rows
            state.pageData2.total = data.total
        },
        fz3(state, data) {
            state.pageData3.rows = data.rows
            state.pageData3.total = data.total
        },
        fz4(state, data) {
            state.pageData4.rows = data.rows
            state.pageData4.total = data.total
        },
        fz5(state, data) {
            state.pageData5.rows = data.rows
            state.pageData5.total = data.total
        },
        // changepageSize(state,size){
        //     state.pageData.pageSize = size;
        // },
        changepageSize2(state, size) {
            state.pageData2.pageSize = size;
        },
        changePage(state, page) {
            state.pageData.currentPage = page;
        },
        changePage2(state, page) {
            state.pageData2.currentPage = page;
        },
        changePage3(state, page) {
            state.pageData3.currentPage = page;
        },
        changePage4(state, page) {
            state.pageData4.currentPage = page;
        },
        changePage5(state, page) {
            state.pageData5.currentPage = page;
        },
    },
    actions: {
        async getlist(context, searchData) {
            let ll = {
                pageSize: context.state.pageData.pageSize,
                currentPage: context.state.pageData.currentPage,
                orderState: "等待确认",
                ...searchData,
                // searchType:"createTime",
                // searchValue:"2020/7/1 20:20",
            }
            const { data } = await axios.get('orders/getOrders', { params: ll })
            console.log(data)
            context.commit("fz", data)
        },
        async getlist2(context) {
            let ll = {
                pageSize: context.state.pageData2.pageSize,
                currentPage: context.state.pageData2.currentPage,
                orderState: "待支付"
            }
            const { data } = await axios.get('orders/getOrders', { params: ll })
            console.log(data)
            context.commit("fz2", data)
        },
        async getlist3(context) {
            let ll = {
                pageSize: context.state.pageData3.pageSize,
                currentPage: context.state.pageData3.currentPage,
                orderState: "交易失败"
            }
            const { data } = await axios.get('orders/getOrders', { params: ll })
            console.log(data)
            context.commit("fz3", data)
        },
        async getlist4(context) {
            let ll = {
                pageSize: context.state.pageData4.pageSize,
                currentPage: context.state.pageData4.currentPage,
                orderState: "已支付"
            }
            const { data } = await axios.get('orders/getOrders', { params: ll })
            console.log(data)
            context.commit("fz4", data)
        },
        async getlist5(context) {
            let ll = {
                pageSize: context.state.pageData5.pageSize,
                currentPage: context.state.pageData5.currentPage,
                orderState: "交易完成"
            }
            const { data } = await axios.get('orders/getOrders', { params: ll })
            console.log(data)
            context.commit("fz5", data)
        },

        handleCurrentChange(context, val) {
            // context.state.pageData.currentPage = val
            context.commit('changePage', val)
            context.dispatch('getlist')
        },
        handleSizeChange(context, val) {
            console.log(val)
            context.state.pageData.pageSize = val
            context.dispatch('getlist')
        },
        handleCurrentChange2(context, val) {
            context.commit('changePage2', val)
            context.dispatch('getlist2')
        },
        handleSizeChange2(context, val) {
            console.log(context.state.pageData2.pageSize)
            // context.state.pageData2.pageSize = val

            context.commit('changepageSize2', val)
            context.dispatch('getlist2')
        },
        handleCurrentChange3(context, val) {
            context.commit('changePage3', val)
            context.dispatch('getlist3')
        },
        handleSizeChange3(context, val) {
            context.state.pageData3.pageSize = val
            context.dispatch('getlist3')
        },
        handleSizeChange4(context, val) {
            context.commit('changePage4', val)
            context.dispatch('getlist4')
        },
        handleSizeChange4(context, val) {
            context.state.pageData4.pageSize = val
            context.dispatch('getlist4')
        },
        handleSizeChange5(context, val) {
            context.commit('changePage5', val)
            context.dispatch('getlist5')
        },
        handleSizeChange5(context, val) {
            context.state.pageData5.pageSize = val
            context.dispatch('getlist5')
        },
    }
}